﻿	var pub_is_send = false;
	var pub_qian_day = 0;
	var today_index = -1;
	var today = 0;
	var ml = '';

	$('body').css('background','url(/x_res/admin_app/act_sign/act_sign-0001/img/bg.png) 0 0/100% 100% no-repeat');

	function func_page_init__success(data, textStatus, jqXHR) {
		pub_is_send = data.page.is_chou;

		var today_l = data.date.split(' ')[0];
		today = today_l.substring(today_l.length - 2, today_l.length);
		today = parseInt(today);


		pub_qian_day = data.page.sign_list_count;
		$(".qian_day").find('span').html(pub_qian_day);
		console.log(parseInt(today))

		var sign_list = data.page.sign_list;
		for (var i = 0; i < sign_list.length; i++)
		{
			var item = sign_list[i];
			if (item != null)
			{
				//签了
				var is_today = isToday(item.date);
				var coin = '×' + item.entity_actlog.actlog_int_00;
				if (is_today) {
					//      				today_index = i;
					var html = '<div class="item" id="item' + (i + 1) + '">' +
									'<img src="/x_res/admin_app/act_sign/act_sign-0001/img/today.png"/>' +
									'<span class="coin_n">' + coin + '</span>' +
								'</div>';
				} else {

					var html = '<div class="item" id="item' + (i + 1) + '">' +
									'<img src="/x_res/admin_app/act_sign/act_sign-0001/img/used.png"/>' +
								'</div>';
				}

			} else {//没签
				if (i >= today - 1) {
					var html = '<div class="item" id="item' + (i + 1) + '">' +
								'<img src="/x_res/admin_app/act_sign/act_sign-0001/img/nomal.png"/>' +
								'<span class="normal">' + (i + 1) + '</span>' +
							'</div>';
				} else {
					var html = '<div class="item" id="item' + (i + 1) + '">' +
								'<img src="/x_res/admin_app/act_sign/act_sign-0001/img/expire.png"/>' +
							'</div>';
				}

			}

			$(".day_list").append(html);
		}
	}

	/*
	*	create by nydia
	*	create date : 2015-6-25
	*	name: 扫红包 默认版
	*	version: v1.00
	*/

	$(function () {
		$(".btn_sure").click(function () {
			$(".page_success").fadeOut();
			//		$('.btn_qian').addClass('gray');

			$("#item" + today).addClass('bounceOut');
			setTimeout(function () {
				$("#item" + today).removeClass('bounceOut').empty();
				$("#item" + today).addClass('bounceIn').append(ml);
			}, 800)
		})
		$(".btn_qian").click(function () {
			if (pub_is_send) {
				func_alert('今天已经签到过了');
			}
			else {
				func_chou();
			}
		})
	});


	function func_chou__success(data, textStatus, jqXHR) {
		console.log(data);
		console.log(textStatus);
		console.log(jqXHR);

		if (data.errcode == 0) {
			pub_is_send = true;
			var coin = data.fun;

			$(".tip").html('你已成功签到' + (pub_qian_day + 1) + '天<br />恭喜获得' + coin + '个金币<br />记得每天都要来哦~')

			$(".page_success").show();
			ml = '<img src="/x_res/admin_app/act_sign/act_sign-0001/img/today.png"/><span class="coin_n">×' + coin + '</span>';


			$(".qian_day").find('span').html(pub_qian_day + 1);
		}
		else {
			func_alert(data.errmsg);
		}
	}

	function isToday(str) {
		var d = new Date(str.replace(/-/g, "/"));
		var todaysDate = new Date();
		if (d.setHours(0, 0, 0, 0) == todaysDate.setHours(0, 0, 0, 0)) {
			return true;
		} else {
			return false;
		}
	}


	(function (doc, win) {
		var docEl = doc.documentElement,
		  resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
		  recalc = function () {
		  	var clientWidth = docEl.clientWidth;
		  	if (!clientWidth) return;
		  	docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
		  };

		if (!doc.addEventListener) return;
		win.addEventListener(resizeEvt, recalc, false);
		doc.addEventListener('DOMContentLoaded', recalc, false);
	})(document, window);